package cz.fit.vutbr.pis2012.augeaswh.control.ekonom.supplier;

import java.io.Serializable;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

import org.richfaces.component.SortOrder;

@ManagedBean
@SessionScoped
public class SupplierSortingBean implements Serializable {
	
	private static final long serialVersionUID = 9125973855028434484L;
	private SortOrder nameOrder = SortOrder.ascending;
    private SortOrder icoOrder = SortOrder.unsorted;
    private SortOrder dicOrder = SortOrder.unsorted;
    private SortOrder accountNumberOrder = SortOrder.unsorted;
    private SortOrder bankNameOrder = SortOrder.unsorted;
    private SortOrder ibanOrder = SortOrder.unsorted;
        
    public void sortByName() {
        icoOrder = SortOrder.unsorted;
        dicOrder = SortOrder.unsorted;
        accountNumberOrder = SortOrder.unsorted;
        bankNameOrder = SortOrder.unsorted;
        ibanOrder = SortOrder.unsorted;
        
        if (nameOrder.equals(SortOrder.ascending)) {
            setNameOrder(SortOrder.descending);
        } else {
        	setNameOrder(SortOrder.ascending);
        }
    }
    
    public void sortByIco() {
        nameOrder = SortOrder.unsorted;
        dicOrder = SortOrder.unsorted;
        accountNumberOrder = SortOrder.unsorted;
        bankNameOrder = SortOrder.unsorted;
        ibanOrder = SortOrder.unsorted;
        
        if (icoOrder.equals(SortOrder.ascending)) {
            setIcoOrder(SortOrder.descending);
        } else {
        	setIcoOrder(SortOrder.ascending);
        }
    }
    
    public void sortByDic() {
        nameOrder = SortOrder.unsorted;
        icoOrder = SortOrder.unsorted;
        accountNumberOrder = SortOrder.unsorted;
        bankNameOrder = SortOrder.unsorted;
        ibanOrder = SortOrder.unsorted;
        
        if (dicOrder.equals(SortOrder.ascending)) {
            setDicOrder(SortOrder.descending);
        } else {
        	setDicOrder(SortOrder.ascending);
        }
    }
    
    public void sortByAccountNumber() {
        nameOrder = SortOrder.unsorted;
        icoOrder = SortOrder.unsorted;
        dicOrder = SortOrder.unsorted;
        bankNameOrder = SortOrder.unsorted;
        ibanOrder = SortOrder.unsorted;
        
        if (accountNumberOrder.equals(SortOrder.ascending)) {
            setAccountNumberOrder(SortOrder.descending);
        } else {
        	setAccountNumberOrder(SortOrder.ascending);
        }
    }
    
    public void sortByBankName() {
        nameOrder = SortOrder.unsorted;
        icoOrder = SortOrder.unsorted;
        dicOrder = SortOrder.unsorted;
        accountNumberOrder = SortOrder.unsorted;
        ibanOrder = SortOrder.unsorted;
        
        if (bankNameOrder.equals(SortOrder.ascending)) {
            setBankNameOrder(SortOrder.descending);
        } else {
        	setBankNameOrder(SortOrder.ascending);
        }
    }
    
    public void sortByIban() {
        nameOrder = SortOrder.unsorted;
        icoOrder = SortOrder.unsorted;
        dicOrder = SortOrder.unsorted;
        accountNumberOrder = SortOrder.unsorted;
        bankNameOrder = SortOrder.unsorted;
        
        if (ibanOrder.equals(SortOrder.ascending)) {
            setIbanOrder(SortOrder.descending);
        } else {
        	setIbanOrder(SortOrder.ascending);
        }
    }

	public SortOrder getNameOrder() {
		return nameOrder;
	}

	public void setNameOrder(SortOrder nameOrder) {
		this.nameOrder = nameOrder;
	}

	public SortOrder getIcoOrder() {
		return icoOrder;
	}

	public void setIcoOrder(SortOrder icoOrder) {
		this.icoOrder = icoOrder;
	}

	public SortOrder getDicOrder() {
		return dicOrder;
	}

	public void setDicOrder(SortOrder dicOrder) {
		this.dicOrder = dicOrder;
	}

	public SortOrder getAccountNumberOrder() {
		return accountNumberOrder;
	}

	public void setAccountNumberOrder(SortOrder accountNumberOrder) {
		this.accountNumberOrder = accountNumberOrder;
	}

	public SortOrder getBankNameOrder() {
		return bankNameOrder;
	}

	public void setBankNameOrder(SortOrder bankNameOrder) {
		this.bankNameOrder = bankNameOrder;
	}

	public SortOrder getIbanOrder() {
		return ibanOrder;
	}

	public void setIbanOrder(SortOrder ibanOrder) {
		this.ibanOrder = ibanOrder;
	}
}
